<?php
/*
 * The Sample 2 shows that a MainProcess fork a child
 *  and check it nonblockingly.
 */
require_once dirname(__FILE__).'/common.inc.php';
/*
 * function mark() is defined in common.inc.php.
 * It echos a line with PID and time.
 * e.g. mark('MAIN START');//echo MAIN START	pid:6819	time:47:53
 */
mark('SAMPLE 2 START');

class Sample2 implements IFeng\Process\Runnable {
	/**
	 * @see IFeng\Process\Runnable::run()
	 */
	public function run() {
		mark('---CHILD START');
		sleep(3);
		mark('---CHILD END');
	}
}

$child = IFeng\Process\Process::current()->fork(new Sample2());
while (true) {
	mark('CHECK...');
	if(!$child->isAlive()) {
		mark('CHECK: CHILD has exited');
		mark('-IS NORMAL EXIT: '.($child->getExitStatus()->isNormalExit()? 'TRUE' :'FALSE'));
		//check again, it still returns false
		mark('CHECK AGAIN: '.($child->isAlive()===false ? 'FALSE' : 'TRUE'));
		break;
	}
	usleep(3000*300);
}

mark('SAMPLE 2 END');